// 引入UI组件
import CountUI from "../../components/Count/index.jsx";
import {createIncrementAction,createDecrementAction,createAsyncIncrementAction} from "../../redux/count_action.js";
// 引入connect
import {connect} from "react-redux";

/**
 * mapStateToProps函数返回的是一个对象，用于传递状态
 */
function mapStateToProps(state){
    return {
        count:state
    };
};

/*
*  mapDispatchToProps函数返回的是一个对象，用于操作状态的方法
*/
function mapDispatchToProps(dispatch){
    return {
        increment:(data)=>{
            dispatch(createIncrementAction(data));
        },
        decrement:(data)=>{
            dispatch(createDecrementAction(data));
        },
        asyncIncrement:(data,time)=>{
            dispatch(createAsyncIncrementAction(data,time));
        }
    };
};

export default connect(mapStateToProps,mapDispatchToProps)(CountUI);